﻿using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Hangfire;
using Hangfire.Common;
using Microsoft.Ajax.Utilities;

namespace Hello_Hangfire.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        /// <summary>
        /// 基于队列的任务处理
        /// </summary>
        /// <returns></returns>
        public ActionResult Enqueue()
        {
            //基于队列的任务处理
            var jobId = HangfireUtil.Enqueue(
                    () => Class1.Log("Enqueue"));

            //延迟任务执行
            jobId = HangfireUtil.Schedule(
                () => Class1.Log("Schedule 60s"),
                TimeSpan.FromSeconds(60));

       

            //string cronString = Cron.MinuteInterval(2);

            //string cronStringDesc=CronExpressionDescriptor.ExpressionDescriptor.GetDescription("*/2 * * * * *");

            //定时任务执行（循环）
            HangfireUtil.RecurringJobAddOrUpdate(() => Class1.Log("RecurringJob.AddOrUpdate"), Cron.Minutely);


            ////延迟任务执行
            //jobId = HangfireUtil.Enqueue(
            //        () => Class1.Log("BackgroundJob.ContinueWith.Task1"));

            ////延续性任务执行（第一个任务执行后执行第二个任务）
            //jobId = HangfireUtil.ContinueWith(jobId, () => Class1.Log("BackgroundJob.ContinueWith.Task2"));

            return View();
        }




    }
}